<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : context_enable.xsl
    Created on : 7. Mai 2008, 14:20
    Author     : philipp.maschke
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:variable name="time">
	<xsl:value-of  select="document('http://xobjex.com/cgi-bin/date.pl')/date/utc/@stamp"/>
    </xsl:variable>
    
    <xsl:template match="/">
        <data>
            <xsl:apply-templates select="//metadata[contains(@place_id,'pl_context')]"/>
            <!-- current assumption: only one context place exists -->
        </data>
    </xsl:template>

    <xsl:template match="metadata">
        <metadata>
          <xsl:attribute name="target_place">
            <xsl:value-of select="@target_place"/>
          </xsl:attribute>
          <xsl:attribute name="name">
            <xsl:value-of select="@name"/>
          </xsl:attribute>
          <xsl:attribute name="place_id">
            <xsl:value-of select="@placeid"/>
          </xsl:attribute>
            <xsl:apply-templates/>
        </metadata>
    </xsl:template>
    
    <xsl:template match="metadata/status">
        <status>enabled</status>
    </xsl:template>

    <xsl:template match="metadata/actions">
        <actions>
            <action>
                <name>enable</name>
                <time><xsl:copy-of select="$time" /></time>
                <user><xsl:copy-of select="system" /></user>
            </action>
            <xsl:copy-of select="*"/>
        </actions>
    </xsl:template>
    
    <xsl:template match="metadata/*">
         <xsl:copy-of select="."/>  
    </xsl:template>

</xsl:stylesheet>
